//
//  WithdrawPlatformView.swift
//  LeTu
//
//  Created by g1 on 2024/1/4.
//

import UIKit

class WithdrawPlatformView: UIView {

    var isShowTopLineView: Bool = true {
        didSet {
            topLineView.isHidden = !isShowTopLineView
        }
    }
    
    var isShowBottomLineView: Bool = true {
        didSet {
            bottomLineView.isHidden = !isShowBottomLineView
        }
    }
    
    init(icon: String, name: String, detail: String) {
        super.init(frame: .zero)
        
        configUI()
        
        imgView.image = UIImage(named: icon)
        nameLabel.text = name
        detailLabel.text = detail
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        DispatchQueue.main.async {
            self.topLineView.addDashedLine(color: .app_lineColor, dashedLineWidth: 6, lineHeight: CGFloat.app_lineHieght)
            self.bottomLineView.addDashedLine(color: .app_lineColor, dashedLineWidth: 6, lineHeight: CGFloat.app_lineHieght)
        }
    }
    static func getViewHeight() -> CGFloat {
        return 62
    }
    func updateDetail(_ detail: String) {
        detailLabel.text = detail
    }

    // MARK: - configUI
    func configUI() {
        
        addSubview(topLineView)
        addSubview(bottomLineView)
        addSubview(backView)
        backView.addSubview(imgView)
        backView.addSubview(nameLabel)
        backView.addSubview(detailLabel)
        
        topLineView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(1)
        }
        bottomLineView.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(topLineView)
        }
        backView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(topLineView.snp.bottom)
            make.bottom.equalTo(bottomLineView.snp.top)
        }
        imgView.snp.makeConstraints { make in
            make.left.centerY.equalToSuperview()
            make.width.height.equalTo(26)
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(12)
            make.centerY.equalToSuperview()
        }
        detailLabel.snp.makeConstraints { make in
            make.right.centerY.equalToSuperview()
        }
        
    }
    private lazy var topLineView = UIView()
    private lazy var backView = UIView()
    private lazy var imgView: UIImageView = {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFit
        return imgView
    }()
    private lazy var nameLabel: UILabel = {
        let nameLabel = UILabel()
        nameLabel.font = kSetPingFangRegular(14)
        return nameLabel
    }()
    private lazy var detailLabel: UILabel = {
        let detailLabel = UILabel()
        detailLabel.font = kSetPingFangRegular(14)
        detailLabel.textColor = .app_textGrayColor
        detailLabel.textAlignment = .right
        return detailLabel
    }()
    private lazy var bottomLineView = UIView()

    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
